package com.mvc.common.web.freemarker;

import java.io.IOException;
import java.util.Map;
import java.util.UUID;

import org.apache.commons.lang.StringUtils;

import freemarker.core.Environment;
import freemarker.template.TemplateDirectiveBody;
import freemarker.template.TemplateDirectiveModel;
import freemarker.template.TemplateException;
import freemarker.template.TemplateModel;

/**  
  * 文件名：UUIDDirective.java  
  * UUID生成器
  * 内容信息：  
  * 日期：2012-10-8  
  * Copyright 黑狼  Corporation 2012   
  * 版权所有  
  *  
  */ 
public class UUIDDirective implements TemplateDirectiveModel {
	public void execute(Environment env, Map params, TemplateModel[] loopVars,
			TemplateDirectiveBody body) throws TemplateException, IOException {
		String uuid = UUID.randomUUID().toString();
		uuid = StringUtils.remove(uuid, '-');
		env.getOut().append(uuid);
	}
}
